<template>
  <div class="app-container">
    <!--表单组件-->
    <!-- 字典列表 -->
    <el-row :gutter="10">
      <el-col :xs="24" :sm="24" :md="10" :lg="11" :xl="11" style="margin-bottom: 10px">
        <el-card class="box-card">
          <!--工具栏-->
          <div class="head-container">
            <div v-if="crud.props.searchToggle">
              <!-- 搜索 -->
              <!-- 搜索 -->
              <el-input v-model="query.nameCn" clearable placeholder="区域名称" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
              <rrOperation :crud="crud" />
            </div>
            <crudOperation :permission="permission" />
          </div>
          <!--表格渲染-->
          <el-table ref="table" v-loading="crud.loading" :data="crud.data" stripe highlight-current-row style="width: 100%;" @selection-change="crud.selectionChangeHandler" @current-change="handleCurrentChange">
            <el-table-column type="selection" width="55" />
            <el-table-column prop="nameCn" label="区域名称"      >
              <template slot-scope="scope">
                <span>{{ scope.row.nameCn }}</span><br>
                <span>{{ scope.row.nameEn }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="status" label="是否可用"      >
              <template slot-scope="scope">
                {{ dict.label.true_false[scope.row.status] }}
              </template>
            </el-table-column>
            <el-table-column label="区域类型"       />
          </el-table>
          <!--分页组件-->
          <pagination />
        </el-card>
      </el-col>
      <!-- 字典详情列表 -->
      <el-col :xs="24" :sm="24" :md="14" :lg="13" :xl="13">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>大厦</span>
            <el-button
              v-if="checkPer(['admin','dict:add']) && this.$refs.dictDetail && this.$refs.dictDetail.query.dictId"
              class="filter-item"
              size="mini"
              style="float: right;padding: 4px 10px"
              type="primary"
              icon="el-icon-plus"
              @click="$refs.dictDetail && $refs.dictDetail.crud.toAdd()"
            >新增</el-button>
          </div>
          <orderRegion ref="orderRegion" :permission="permission" />
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import orderRegion from './OrderRegionChild'
import CRUD, { presenter, header, form } from '@crud/crud'
import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'
import rrOperation from '@crud/RR.operation'
import crudOrderRegion from '@/api/oms/orderRegion'

const defaultForm = { id: null, nameCn: null, nameEn: null, status: false, regionType: 0, parentId: null }

export default {
  name: 'OrderRegion',
  components: { crudOperation, pagination, rrOperation, orderRegion },
  cruds() {
    return [
      CRUD({ title: '字典', url: 'orderRegion/page', sort: 'id:desc', query: { parentId: 0 }, crudMethod: { ...crudOrderRegion }, optShow: {
        add: false,
        edit: false,
        del: false,
        reset: false
      }
      })
    ]
  },
  mixins: [presenter(), header(), form(defaultForm)],
  dicts: ['true_false', 'regionType'],
  data() {
    return {
      queryTypeOptions: [
        { key: 'nameCn', display_name: '中文区域名称' },
        { key: 'nameEn', display_name: '英文区域名称' },
        { key: 'status', display_name: '是否可用' },
        { key: 'regionType', display_name: '区域类型' }
      ],
      rules: {
        nameCn: [
          { required: true, message: '中文区域名称不能为空', trigger: 'blur' }
        ],
        nameEn: [
          { required: true, message: '英文区域名称不能为空', trigger: 'blur' }
        ],
        status: [
          { required: true, message: '是否可用不能为空', trigger: 'blur' }
        ],
        regionType: [
          { required: true, message: '区域类型不能为空', trigger: 'blur' }
        ]
      },
      permission: {
        add: ['admin', 'orderRegion:add'],
        edit: ['admin', 'orderRegion:edit'],
        del: ['admin', 'orderRegion:del']
      }
    }
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      if (this.$refs.orderRegion) {
        this.$refs.orderRegion.query.parentId = null
      }
      return true
    },
    // 选中字典后，设置字典详情数据
    handleCurrentChange(val) {
      if (val) {
        this.$refs.orderRegion.query.parentId = val.id
        this.$refs.orderRegion.parentId = val.id
        this.$refs.orderRegion.crud.toQuery()
      }
    }
  }
}
</script>

<style scoped>
</style>
